package cn.iocoder.yudao.module.tms.service.attachmentinfo;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.tms.controller.admin.attachmentinfo.vo.*;
import cn.iocoder.yudao.module.tms.dal.dataobject.attachmentinfo.AttachmentInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.tms.dal.mysql.attachmentinfo.AttachmentInfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;

/**
 * 公司附件信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class AttachmentInfoServiceImpl implements AttachmentInfoService {

    @Resource
    private AttachmentInfoMapper attachmentInfoMapper;

    @Override
    public Long createAttachmentInfo(AttachmentInfoSaveReqVO createReqVO) {
        // 插入
        AttachmentInfoDO attachmentInfo = BeanUtils.toBean(createReqVO, AttachmentInfoDO.class);
        attachmentInfoMapper.insert(attachmentInfo);

        // 返回
        return attachmentInfo.getId();
    }

    @Override
    public void updateAttachmentInfo(AttachmentInfoSaveReqVO updateReqVO) {
        // 校验存在
        validateAttachmentInfoExists(updateReqVO.getId());
        // 更新
        AttachmentInfoDO updateObj = BeanUtils.toBean(updateReqVO, AttachmentInfoDO.class);
        attachmentInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteAttachmentInfo(Long id) {
        // 校验存在
        validateAttachmentInfoExists(id);
        // 删除
        attachmentInfoMapper.deleteById(id);
    }

    @Override
        public void deleteAttachmentInfoListByIds(List<Long> ids) {
        // 删除
        attachmentInfoMapper.deleteByIds(ids);
        }


    private void validateAttachmentInfoExists(Long id) {
//        if (attachmentInfoMapper.selectById(id) == null) {
//            throw exception(ATTACHMENT_INFO_NOT_EXISTS);
//        }
    }

    @Override
    public AttachmentInfoDO getAttachmentInfo(Long id) {
        return attachmentInfoMapper.selectById(id);
    }

    @Override
    public PageResult<AttachmentInfoDO> getAttachmentInfoPage(AttachmentInfoPageReqVO pageReqVO) {
        return attachmentInfoMapper.selectPage(pageReqVO);
    }

}